﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SharpDropBoxClient;

namespace System.IO.DropBox
{
    public interface IDropBoxSetup
    {
        IDropBoxApp DropBoxApp { get; set; }

        void SetKeyAndSecret(string key, string secret);
    }

    public class DropBoxSetup : IDropBoxSetup
    {
        #region Singleton pattern From Jon Skeet - http://www.yoda.arachsys.com/csharp/singleton.html

        static readonly DropBoxSetup instance = new DropBoxSetup();

        // Explicit static constructor to tell C# compiler
        // not to mark type as beforefieldinit
        static DropBoxSetup()
        {
        }

        DropBoxSetup()
        {
        }

        public static DropBoxSetup Instance
        {
            get
            {
                return instance;
            }
        }

        #endregion Singleton pattern From Jon Skeet - http://www.yoda.arachsys.com/csharp/singleton.html

        #region IDropBoxSetup Members

        public IDropBoxApp DropBoxApp
        {
            get;
            set;
        }

        public void SetKeyAndSecret(string Key, string secret)
        {
            this.DropBoxApp = new DropBoxApp(Key, secret);
        }

        public void Login(string userName, string password, Action<bool, Exception> callback)
        {
            if (this.DropBoxApp == null)
            {
                callback(false, new IOException("Must Set Key/Secret first before calling login!"));
            }
            else
            {
                this.DropBoxApp.LoginAndGetAuthCredentials(userName, password, (result, ex) =>
                {
                    callback(result, ex);
                });
            }
        }

        #endregion IDropBoxSetup Members
    }
}